Skip to content

Clear idp cookie after succesful SSO#47569

Open
ksykulev wants to merge 2 commits into
mainfrom
47343-idp-cookie
Open

Clear idp cookie after succesful SSO#47569
ksykulev wants to merge 2 commits into
mainfrom
47343-idp-cookie

Conversation

@ksykulev

@ksykulev ksykulev commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #47343

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • New Features
    • Added support for identity provider (IdP) UUID in enrollment flows for both fully-managed and non-fully-managed scenarios.
    • SSO authentication cookie is now cleared automatically after successful authentication.
    • Enhanced enrollment process with improved identity provider validation and fallback authentication handling.

Copilot AI review requested due to automatic review settings June 13, 2026 22:29
@ksykulev ksykulev requested review from a team as code owners June 13, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

This PR updates the end-user OTA enrollment flow to prevent reusing a stale IdP identity across enrollments by clearing the BYOD IdP cookie after successful SSO, and by plumbing an IdP UUID into the Android enrollment token request when needed.

Changes:

  • Clears the BYOD IdP cookie after creating an Android enrollment token (via SetCookies on the response).
  • Passes an IdpUUID value through the /enroll HTML template and into the Android enrollment token fetch as idp_uuid.
  • Updates the Android enrollment token request decoder to accept idp_uuid from the query string before falling back to the cookie.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/service/frontend.go Passes IdpUUID into the enroll template and clears the BYOD IdP cookie before rendering the enroll page (needs adjustment to avoid breaking iOS/iPadOS flows).
server/mdm/android/service/service.go Accepts idp_uuid query param for enrollment token requests before checking the cookie.
server/mdm/android/service.go Adds SetCookies to clear the BYOD IdP cookie after successfully creating an enrollment token; introduces a cookie name constant.
frontend/templates/enroll-ota.html Appends idp_uuid to the Android enrollment token fetch URL when present.
changes/47343-idp-cookie User-visible change entry (content excluded from review).
Files excluded by content exclusion policy (1)
  • changes/47343-idp-cookie

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service/frontend.go
Comment thread server/mdm/android/service.go Outdated
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.07692% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.18%. Comparing base (268c918) to head (44419c7).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
server/service/frontend.go 26.31% 12 Missing and 2 partials ⚠️
server/mdm/android/service/service.go 14.28% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #47569      +/-   ##
==========================================
- Coverage   67.19%   67.18%   -0.01%     
==========================================
  Files        3616     3616              
  Lines      229016   229051      +35     
  Branches    11785    11931     +146     
==========================================
+ Hits       153887   153890       +3     
- Misses      61302    61326      +24     
- Partials    13827    13835       +8     
Flag Coverage Δ
backend 68.83% <23.07%> (-0.02%) ⬇️
frontend 57.98% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bf7190e9-7aa1-4d24-aa99-c1121d77ca85

📥 Commits

Reviewing files that changed from the base of the PR and between f988110 and 44419c7.

📒 Files selected for processing (1)
  • server/service/frontend.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/service/frontend.go

Walkthrough

The PR fixes fully-managed Android enrollment by threading an IdP UUID through the enrollment flow. ServeEndUserEnrollOTA now clears the BYOD IdP cookie and extracts idpUUID from enrollment_reference when authRequired is true and fully_managed equals "true", passing it to the updated renderEnrollPage helper, which exposes it as IdpUUID in the template context. The enrollment page script reads that value and appends it as an idp_uuid query parameter when calling the enrollment-token endpoint. On the server side, enrollmentTokenRequest.DecodeRequest uses the query parameter directly when present, bypassing cookie lookup.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: clearing the IdP cookie after successful SSO authentication for fully-managed Android enrollment.
Description check ✅ Passed The PR description includes the related issue reference and checked relevant checklist items, but lacks implementation details about how the fix addresses the issue.
Linked Issues check ✅ Passed The code changes directly address issue #47343 by implementing IdP cookie clearing and UUID passing to enable SSO prompt during fully-managed Android enrollment.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving the linked issue: adding change note, updating enrollment template, modifying enrollment token request handling, and clearing IdP cookie after authentication.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 47343-idp-cookie

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/mdm/android/service.go (1)

10-10: ⚡ Quick win

Use the shared BYOD IdP cookie constant instead of duplicating the literal.

byodIdpCookieName duplicates a cross-layer contract value. If the canonical cookie name changes, this cookie-clearing path can silently break.

Proposed change
 import (
 	"context"
 	"net/http"
 
+	shared_mdm "github.com/fleetdm/fleet/v4/pkg/mdm"
 	"google.golang.org/api/androidmanagement/v1"
 )
-
-const byodIdpCookieName = "__Host-FLEETBYODIDP"
@@
 	http.SetCookie(w, &http.Cookie{
-		Name:     byodIdpCookieName,
+		Name:     shared_mdm.BYODIdpCookieName,
 		Value:    "",
 		Path:     "/",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/mdm/android/service.go` at line 10, The constant byodIdpCookieName is
currently defined as a local literal value "__Host-FLEETBYODIDP" in this file,
which duplicates the canonical definition elsewhere in the codebase. Remove the
local constant definition and instead import and use the shared
byodIdpCookieName constant from its canonical location (likely in a shared
utilities or constants package) to ensure consistency across layers and prevent
the cookie-clearing logic from breaking if the canonical cookie name is updated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/mdm/android/service/service.go`:
- Around line 500-506: The idp_uuid query parameter is being accepted directly
without server-side validation, allowing any caller with an enroll_secret to
bind an enrollment to any IdP UUID without fresh authentication. Remove or
significantly restrict the code block that extracts idp_uuid from the query
parameter and directly populates it in the enrollmentTokenRequest struct.
Instead, only accept idp_uuid when it is cryptographically bound to
server-trusted state, such as validation against an active session cookie or a
signed one-time token generated by the server during a prior authenticated
operation. Ensure that the enrollmentTokenRequest construction validates the
identity proof before incorporating any IdP identifier.

---

Nitpick comments:
In `@server/mdm/android/service.go`:
- Line 10: The constant byodIdpCookieName is currently defined as a local
literal value "__Host-FLEETBYODIDP" in this file, which duplicates the canonical
definition elsewhere in the codebase. Remove the local constant definition and
instead import and use the shared byodIdpCookieName constant from its canonical
location (likely in a shared utilities or constants package) to ensure
consistency across layers and prevent the cookie-clearing logic from breaking if
the canonical cookie name is updated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e13046bb-cb8e-4cf9-85df-43df31ff1b85

📥 Commits

Reviewing files that changed from the base of the PR and between 268c918 and f988110.

📒 Files selected for processing (5)
  • changes/47343-idp-cookie
  • frontend/templates/enroll-ota.html
  • server/mdm/android/service.go
  • server/mdm/android/service/service.go
  • server/service/frontend.go

Comment thread server/mdm/android/service/service.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

Files excluded by content exclusion policy (1)
  • changes/47343-idp-cookie

Comment on lines +175 to +178
// Clear the BYOD IdP cookie now that we are about to render the enrollment page.
var idpUUID string
fullyManaged := r.URL.Query().Get("fully_managed")
if authRequired && fullyManaged == "true" {
Comment on lines +175 to +189
// Clear the BYOD IdP cookie now that we are about to render the enrollment page.
var idpUUID string
fullyManaged := r.URL.Query().Get("fully_managed")
if authRequired && fullyManaged == "true" {
idpUUID = r.URL.Query().Get("enrollment_reference")
http.SetCookie(w, &http.Cookie{
Name: shared_mdm.BYODIdpCookieName,
Value: "",
Path: "/",
MaxAge: -1,
Secure: cookieSecure,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
}
Comment on lines +500 to +506
if idpUUID := r.URL.Query().Get("idp_uuid"); idpUUID != "" {
return &enrollmentTokenRequest{
EnrollSecret: enrollSecret,
IdpUUID: idpUUID,
FullyManaged: fullyManaged,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully-managed Android devices aren't seeing EUA prompt during the enrollment

3 participants